<template name="mars-orderStatus">
	<view :style="$s.view_color" class="status-box">
		<view class="b" v-if="order.order_status===-1">
			<button @click="del">删除订单</button>
		</view>
		
		<view class="b" v-if="order.drive_map_status==1">
			<navigator :url="'/pages/order/driver/map_info?id='+order.id">
				<button class="primary">代驾情况</button>
			</navigator>
		</view>
		
		<block  v-if="order.is_auth!=-1">
			<view class="b" v-if="order.order_status===0">
				<navigator :url="'/pages/flow/sign/index?id='+order.id">
					<button class="primary">签名确认</button>
				</navigator>
			</view>
			<view class="b" v-if="order.order_status===1">
				<navigator :url="'/pages/flow/idcard/index?id='+order.id">
					<button class="primary">上传证件</button>
				</navigator>
			</view>
			<view class="b" v-if="order.order_status===2 && order.is_drive!=1">
				<navigator :url="'/pages/order/gain/index?id='+order.id">
					<button class="primary">确认取车</button>
				</navigator>
			</view>
			<block v-if="order.order_status===3">
				<view class="b" v-if="order.is_drive!=1">
					<navigator :url="'/pages/order/back/index?id='+order.id">
						<button class="primary">我要还车</button>
					</navigator>
				</view>
				<view class="b">
					<button class="primary" @click="openRelet()">我要续租</button>
				</view>
			</block>
			<view class="b" v-if="order.order_status===8 || order.order_status===11">
				<navigator :url="'/pages/flow/pay/index?id='+order.id">
					<button class="primary">去付款</button>
				</navigator>
			</view>
		</block>
		
		<view class="b" v-if="order.is_auth==-1">
			<button class="primary" @click="mianya">授权免押</button>
		</view>
		
		<view class="b" v-if="!isList && (order.order_status===2 || order.order_status===3)">
			<navigator :url="'/pages/order/refund/add?id='+order.id">
				<button>申请退款</button>
			</navigator>
		</view>
		<view class="b" v-if="order.order_status===5">
			<navigator :url="'/pages/order/comment/add?id='+order.id+'&cid='+order.car_id">
				<button>评价订单</button>
			</navigator>
		</view>
		<view class="b" v-if="order.order_status===0 || order.order_status===1 || order.order_status===8">
			<button @click="cancel">取消订单</button>
		</view>
		
		<view class="b" v-if="isList">
			<navigator :url="'/pages/order/detail/index?id='+order.id">
				<button>订单明细</button>
			</navigator>
		</view>
		
		<relet-day-select ref="reletDay" :endDate="order.end_date" @dateConfirm="relet"></relet-day-select>
		
	</view>
</template>

<script>
	import { mapState } from 'vuex'
	import $pay from '@/common/pay'
	export default {
		name: 'mars-orderStatus',
		props: {
			order:{
				type:[Object,Array],
				default:{}
			},
			isList:{
				type:[Boolean],
				default:true
			},
			index:{
				type:[Number],
				default:0,
			}
		},
		data() {
			return {
				shape:"circle",
				plain:false,
				size:"normal",
			};
		},
		watch: {
		},
		computed: {
			...mapState({
				$s:state => state.$style,
			})
		},
		methods: {
			openRelet(){
				this.$refs.reletDay.popOpen()
			},
			relet(e){
				this.$store.commit('setReletOrder',{order:this.order,end_date:e})
				this.$c.a('flow/create/index?order_id='+this.order.id)
			},
			//取消订单
			cancel(){
				uni.showModal({
					cancelText: "取消", // 取消按钮的文字  
					confirmText: "确认", // 确认按钮文字 
					title: '温馨提示',
					content: '您确定取消该订单吗?',
					success: res => {
						if (res.confirm) {
							this.$u.api.orderCancel({id:this.order.id}).then(res=>{
								if(res.data){
									this.$c.success('订单已取消')
									this.$emit('refresh',true)
								}
							})
						}
					}
				});
			},
			//删除订单
			del(){
				uni.showModal({
					cancelText: "取消", // 取消按钮的文字  
					confirmText: "确认", // 确认按钮文字 
					title: '删除提示',
					content: '您确定删除该订单吗?',
					success: res => {
						if (res.confirm) {
							this.$u.api.orderDelete({id:this.order.id}).then(res=>{
								if(res.data){
									this.$c.success('订单已删除')
									this.$emit('refresh',true)
								}
							})
						}
					}
				});
			},
			
			// #ifdef MP-ALIPAY
			// 支付宝免押
			mianya(){
				let than=this
				let order_id=this.order.id;
				uni.$u.api.authPay({id:order_id}).then(res=>{
					if(res.status){
						$pay.aliAuthPay(res.data).then(result=>{
							if(result.status){
								//回调通知免押
								uni.$u.api.backMianya({id:order_id}).then(myres=>{
									than.$c.success('免押成功！',"pages/flow/"+myres.data.url+"/index?id="+order_id,4)
								}).catch(e=>{
									this.$c.info(e)
								})
							}else{
								this.$c.info(result.tips)
							}
						}).catch(e=>{
							this.$c.info(e)
						})
					}
				})
			},
			// #endif
		}
	};
</script>

<style lang="scss">
	.status-box{
		display: flex;
		justify-content: flex-end;
		align-items: center;
		flex-direction: row;
	}
	.status-box .b{
		margin-left: 20rpx;
	}
	
	.b button{
		font-size: 26rpx;
		line-height: 70rpx;
		height: 70rpx;
		width: 180rpx;
		border-radius: 50rpx 50rpx 50rpx 50rpx;
	}
	.b .primary{
		border: 0rpx;
		background-color: var(--view-theme);
		color: var(--view-fontcolor);
	}
</style>
